<template>
  <div class="hello">
    <Form :model="ruleForm" :rules="rules" ref="loginForm">
      <FormItem label="用户名" prop="name">
        <FInput v-model="ruleForm.name" placeholder="请输入用户名"></FInput>
      </FormItem>
      <FormItem label="密码" prop="pass">
        <FInput v-model="ruleForm.pass" placeholder="请输入密码"></FInput>
      </FormItem>

      <FormItem>
        <button @click="handleLogin">登录</button>
      </FormItem>
    </Form>
    <br />
    <p>{{ msg }}</p>
  </div>
</template>

<script>
import FInput from "@/components/form/FInput.vue";
import FormItem from "@/components/form/FormItem.vue";
import Form from "@/components/form/Form.vue";

import create from "@/utils/create";
import Notice from "@/components/Notice";
export default {
  name: "HelloWorld",
  components: {
    FInput,
    FormItem,
    Form,
  },
  data() {
    return {
      msg: "张三",

      ruleForm: {
        name: "",
        pass: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        pass: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate((isValid) => {
        if (isValid) {
          console.log("submit...");
        } else {
          console.log("error...");
        }
        const notice = create(Notice, {
          title: "社会你杨哥喊你来搬砖",
          message: isValid ? "请求登录!" : "登录失败!",
          duration: 1000,
        });
        notice.show();
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
